import api from '../../../api-new'
import types from '../../types'

export const getUserInfo = ({ commit, state, rootState }, payload) => {
  const id = payload.loginId || state.loginId
  const loginType = payload.loginType || 'WXID'

  console.log(id, loginType)
  return api.userInfo(id, loginType).then(data => {
    commit(types.GET_USER_INFO, data)
  }).catch(error => {
    console.error(error.message)
  })
}

export const setLoginId = ({ commit, state }, id) => {
  commit(types.SET_LOGIN_ID, id)
}

export const logout = ({ commit }) => {
  commit(types.LOG_OUT)
}
